package com.example.demo.controller;

import com.example.demo.pojo.Administrator;
import com.example.demo.pojo.Comment;
import com.example.demo.pojo.Mysell;
import com.example.demo.service.CommentServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author yanglup
 * @create 2020-12-13 20:27
 */
@RestController
public class CommentController {
    @Autowired
    CommentServer commentServer;

    /**发布评论*/
    @RequestMapping("/wx/commonentadd")
    public Map<String,Object> commonentlist(String openid,String comment_text,String nickName,String avatarUrl,Integer goods_id){
//        System.out.println(goods_id);
//        System.out.println(openid);
//        System.out.println(comment_text);
//        System.out.println(nickName);
        String comment_time=new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        Integer likenumber=0;
        commentServer.commonentadd(openid,comment_time,comment_text,nickName,likenumber,avatarUrl,goods_id);

        Map<String, Object> mymap = new HashMap<>();
        mymap.put("msg", "获取成功");
        mymap.put("status", 200);
        Map<String, Object> map = new HashMap<>();
        map.put("meta", mymap);
        return map;
    }

    /**查询评论列表*/
    @RequestMapping("/wx/commonentlist")
    public Map<String,Object> commonentlist(Integer goods_id){
        List<Comment> list= commentServer.commonentlist(goods_id);

        Map<String, Object> mymap = new HashMap<>();
        mymap.put("msg", "获取成功");
        mymap.put("status", 200);
        Map<String, Object> map = new HashMap<>();
        map.put("message", list);
        map.put("meta", mymap);
        return map;
    }

    /**查询评论列表数量*/
    @RequestMapping("/wx/commonentnumbers")
    public Map<String,Object> commonentnumbers(Integer goods_id){

        Integer commentnumbers= commentServer.commonentnumbers(goods_id);
//        System.out.println(commentnumbers);

        Map<String, Object> mymap = new HashMap<>();
        mymap.put("msg", "获取成功");
        mymap.put("status", 200);
        Map<String, Object> map = new HashMap<>();
        map.put("message", commentnumbers);
        map.put("meta", mymap);
        return map;
    }

    /**喜欢数量加一*/
    @RequestMapping("/wx/commonentlikenumber")
    public Map<String,Object> commonentlikenumber(Integer comment_id){
        //查看是否修改过likenumbe
//        Integer mytestid;
//        try {//查到了
//            Comment mycomment=commentServer.commentidcheck(comment_id);
//            mytestid=mycomment.getComment_id();
//        }catch (Exception e){//没查到
//            mytestid=-1;
//        }

//        if(mytestid!=-1){//即
            commentServer.commonentlikenumber(comment_id);
//        }

        Map<String, Object> mymap = new HashMap<>();
        mymap.put("msg", "获取成功");
        mymap.put("status", 200);
        Map<String, Object> map = new HashMap<>();
        map.put("meta", mymap);
        return map;
    }


}
